#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 1e6+10;
const int mod = 1e9+7;

ll f[N],g[N];
int T,n;
vector<int> G[N];

void dfs(int x,int p){
	for(int y : G[x]){
		if(y == p) continue; dfs(y,x);
		ll tf = f[x] * g[y] % mod + f[y] * g[x] % mod + f[x] + f[y],tg = g[x] * g[y] % mod + g[x] + g[y];
		f[x] = tf % mod; g[x] = tg % mod;
	}
	f[x] += T ? x : 1; g[x]++; f[x] %= mod; g[x] %= mod;
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,T = in;
	for(int i = 1;i < n;i++){
		int u = in,v = in; G[u].pb(v); G[v].pb(u);
	}
	dfs(1,0);
	printf("%lld\n",f[1]);
	return 0;
}
